package com.mywork.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ciko.code.http.Req.SelUserPostInfoListEty;
import com.mywork.R;

import java.util.List;

/**
 * Created by sihailin on 15/12/17.
 */
public class GeneralAdapter extends BaseAdapter {
    private LayoutInflater inflater = null;
    private List<SelUserPostInfoListEty> list;

    public GeneralAdapter(Context context, List<SelUserPostInfoListEty> list) {
        inflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public SelUserPostInfoListEty getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        EnterpriseHolder holder = null;
        SelUserPostInfoListEty item = list.get(position);
        if (convertView == null) {
            // 获得ViewHolder对象
            holder = new EnterpriseHolder();
            // 导入布局并赋值给convertview
            convertView = inflater.inflate(R.layout.cell_enterprise_item, null);
            holder.branchName = (TextView) convertView.findViewById(R.id.branchName);
            holder.departmentName = (TextView) convertView.findViewById(R.id.departmentName);
            // 为view设置标签
            convertView.setTag(holder);
        } else {
            // 取出holder
            holder = (EnterpriseHolder) convertView.getTag();
        }

        holder.branchName.setText(item.getUserName() + "");
        holder.departmentName.setText(item.getDepartmentName() + "");

        return convertView;
    }

    public class EnterpriseHolder {
        public TextView branchName;
        public TextView departmentName;
    }
}
